<template>
	<view class="wf-box" :style="{ paddingTop: totalheight }">
		<HeadNav titleName="历史记录" :topheight="navBarHeight"></HeadNav>
		
		<view class="title-warp">
			<view :class="curTitle == 1 ? 'act-tit' : ''" @click="changeTitle(1)">充值</view>
			<view :class="curTitle == 2 ? 'act-tit' : ''" @click="changeTitle(2)">提现</view>
			<view :class="curTitle == 3 ? 'act-tit' : ''" @click="changeTitle(3)">划转</view>
		</view>
		
		<view class="main-ctr">
			<view class="main-scroll">
				<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="lower">
					<view class="item2" v-for="item in list" @click="details(item)" v-if="curTitle==2">
						<image v-if="item.status!=2&&item.status!=3" src="@/static/img/extractive.png" mode=""></image>
						<image v-else src="@/static/img/extractive_n.png" mode=""></image>
						<view>
							<view class="text_1" :class="item.status!=2&&item.status!=3?'':'col_9'">USDT提现</view>
							<view class="text_3" :class="item.status!=2&&item.status!=3?'':'col_9'">{{ handleState(item.status) }}</view>
							<view class="text_2">{{item.created}}</view>
						</view>
						<view>
							<view :class="item.status!=2&&item.status!=3?'':'col_9'">{{item.status!=2&&item.status!=3?'-':''}}{{item.amount}}USDT</view>
							<view v-if="item.status==0" class="btn" @click.stop="cancel(item.id)">取消</view>
						</view>
					</view>
					
					<view class="scroll-view-item" v-for="item in list" v-else>
						<view class="item-up">
							<!-- {{ item.description }} -->
							<view class="im-lt">
								<view class="iom-fo">
									<!-- curTitle == 1 ? '充值' : '提现' -->
									<text>{{ handleTitle(item.description) }}</text>
									<text v-if="curTitle == 1">({{ handleUdunStatus(item.status) }})</text>
									<text v-if="curTitle == 2">({{ handleWapplyStatus(item.status) }})</text>
								</view>
								<view class="iom-time">{{ item.created }}</view>
							</view>
							<view class="im-rt">
								<text v-if="curTitle != 3">{{ curTitle == 1 ? '+' : '-' }}</text>{{ item.amount }}
							</view>
						</view>
						
						<view class="item-down" v-if="curTitle != 3">
							<!-- {{ curTitle == 1 ? item.tradeId : item.withdrawNo }} -->
							流水号: <text v-if="curTitle == 1">{{ item.tradeId }}</text><text v-if="curTitle == 2">{{ item.withdrawNo }}</text>
						</view>
					</view>
				</scroll-view>
				<!-- <view class="item" v-for="item in list">
					<image src="@/static/img/extractive.png" mode=""></image>
					<view>
						<view class="text_1">USDT提现</view>
						<view>{{ handleState(item.status) }}</view>
						<view class="text_2">{{item.created}}</view>
					</view>
					<view>+{{item.amount}}USDT</view>
				</view> -->
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup-box">
				<view class="popup-title">温馨提示</view>
				<view class="popup-sub">确认要取消当前提现吗？</view>
				<view class="popup-footer">
					<view class="cancle" @click="closePopup()">撤销</view>
					<view class="confim" @click="confim()">确定</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import HeadNav from "@/components/HeadNav"
	import {udunCloudListApi , wapplyRecord , fundRecord,cancelApply} from '@/api/api.js'
	import navBarMixin from '@/mixin/navBarMixin.js'
	export default {
		data() {
			return {
				queryObj: {
					pageNum: 1,
					pageSize: 10,
				},
				
				curTitle: 1,
				// tabIndex: 0,
				list: '',
				total: '',
				
				id: '',
				isAll: false,
			}
		},
		mixins: [navBarMixin],
		components: {
			HeadNav
		},
		onLoad(option) {
			this.record()
		},
		methods: {
			confim() {
				cancelApply({applyId:this.id}).then(res=>{
					console.log(res);
					this.closePopup()
					if (res.code == 0) {
						uni.showToast({
							title: '取消成功!',
							icon: 'none',
							duration: 2000,
						})
						this.wapplyList()
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 3000,
						})
					}
				})
			},
			closePopup() {
				this.$refs.popup.close()
				this.password = ''
			},
			details(e) {
				uni.navigateTo({
					url:'/pages/me/extractiveDetails?info='+JSON.stringify(e)
				})
			},
			cancel(e) {
				this.id = e
				this.$refs.popup.open()
			},
			handleState(e) {
				const arr = ['待审核','提现成功','提现驳回','提现撤销']
				return arr[e]
			},
			back() {
				uni.navigateBack()
			},
			
			handleTitle(text) {
				if(this.curTitle == 1) {
					return '充值USDT'
				}else if(this.curTitle == 2) {
					return '提现USDT'
				}else {
					return text
				}
			},
			
			// 加载充值的
			async record() {
				const res = await udunCloudListApi(this.queryObj)
				
				let cacheList = this.list
				
				this.total = res.data.total
				if (this.queryObj.pageNum == 1) {
					this.list = res.data.records
				}else {
					this.list = cacheList.concat(res.data.records)
				}
				
				this.isAll =  this.list.length == this.total ? 0 : 1
				// this.list = [...res.data.records,...rep.data.records]
				
			},
			
			// 加载提现的
			async wapplyList() {
				const res = await wapplyRecord(this.queryObj)
				
				let cacheList = this.list
				
				this.total = res.data.total
				
				if (this.queryObj.pageNum == 1) {
					this.list = res.data.records
				}else {
					this.list = cacheList.concat(res.data.records)
				}
				
				this.isAll =  this.list.length == this.total ? 0 : 1
				
			},
			
			// 加载划转的
			async transferList() {
				const res = await fundRecord({ pageNum: this.queryObj.pageNum, pageSize: this.queryObj.pageSize, type: 17 })
				
				let cacheList = this.list
				
				this.total = res.data.total
				
				if (this.queryObj.pageNum == 1) {
					this.list = res.data.records
				}else {
					this.list = cacheList.concat(res.data.records)
				}
				this.isAll =  this.list.length == this.total ? 0 : 1
				
			},
			
			lower() {
				// console.log('到底了')
				if(this.isAll) {
					this.queryObj.pageNum++
					// if()
					if(this.curTitle == 1) {
						this.record()
					}else {
						this.wapplyList()
					}
					
					
				}
			},
			
			changeTitle(titType) {
				this.curTitle = titType
				this.queryObj.pageNum = 1
				this.isAll = false
				this.list = []
				if(titType == 1) {
					this.record()
				}else if(titType == 2) {
					this.wapplyList()
				}else {
					this.transferList()
				}
				
			},
			handleUdunStatus(e) {
				const arr = ['待审核','审核成功','审核驳回','交易成功','交易失败']
				return arr[e]
			},
			handleWapplyStatus(e) {
				const arr = ['提现中','提现成功','提现失败']
				return arr[e]
			}
		},
		// onReachBottom() {
		// 	if (this.isAll) {
		// 		this.queryObj.pageNum++;
		// 		if(this.curTitle == 1) {
		// 			this.record()
		// 		}else {
		// 			this.wapplyList()
		// 		}
				
		// 	}
		// }
	}
</script>

<style lang="scss" scoped>
	.wf-box {
		overflow: hidden;
		.title-warp {
			display: flex;
			height: 100rpx;
			padding: 0 30rpx;
			background: #fff;
			view {
				flex: 1;
				line-height: 100rpx;
				text-align: center;
				
				&.act-tit {
					color: #3F93FF;
				}
			}
		}
		
		.main-ctr {
			margin-top: 30rpx;
			padding: 0 30rpx;
			
		}
		.main-scroll {
			height: 1200rpx;
			background: #fff;
			border-radius: 10rpx;
			padding: 30rpx;
			.scroll-Y {
				height: 100%;
				overflow: hidden;
				.scroll-view-item {
					margin-top: 30rpx;
					padding-bottom: 20rpx;
					border-bottom: 2rpx solid #999;
					.item-up {
						display: flex;
						justify-content: space-between;
						align-items: center;
						// padding-bottom: 20rpx;
						.im-lt {
							.iom-fo {
								font-size: 28rpx;
								color: #333;
								text {
									font-size: 24rpx;
									color: #666;
								}
							}
						}
						.im-rt {
							color: red;
							font-size: 50rpx;
						}
					}
					.item-down {
						margin-top: 10rpx;
						font-size: 24rpx;
						color: #666;
						word-break: break-all;
					}
					
					
					
					&:first-child {
						margin-top: 0;
					}
				}
			}
			
		}
		.item2 {
			// height: 150rpx;
			padding: 16rpx 0;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #EEEEEE;
		
			image {
				width: 54rpx;
				height: 54rpx;
				margin-right: 20rpx;
			}
		
			>view {
				.text_1 {
					font-size: 30rpx;
					// color: #333333;
					line-height: 42rpx;
				}
				.text_2 {
					height: 42rpx;
					font-size: 26rpx !important;
					font-weight: 400 !important;
					color: #999999;
					line-height: 42rpx;
					margin-top: 4rpx;
				}
				.text_3 {
					font-size: 26rpx;
					// text-align: right;
					color: #3F93FF;
					margin-top: 8rpx;
					// margin-bottom: 16rpx;
				}
				.btn {
					background-color: #3F93FF;
					color: white;
					text-align: center;
					font-size: 26rpx;
					width: 100rpx;
					margin-left: auto;
					padding: 6rpx 0;
					border-radius: 24rpx;
					margin-top: 20rpx;
				}
				&:nth-of-type(1) {
					flex: 1;
				}
		
				&:nth-of-type(2) {
					font-weight: 500;
					font-size: 30rpx;
					color: #FF5B5B;
				}
			}
		}
	.col_9 {
		color: #999999 !important;
	}
	.popup-box {
		width: 583rpx;
		height: 580rpx;
		border-radius: 20rpx;
		box-sizing: border-box;
		background: #fff;
		background: url('../../static/img/me-32.png') no-repeat;
		background-size: cover;
		overflow: hidden;
		.popup-title {
			font-size: 32rpx;
			color: #333;
			font-weight: bold;
			text-align: center;
			margin-top: 180rpx;
		}
		.popup-text {
			margin: 240rpx 40rpx 0;
			font-size: 28rpx;
		}
		.popup-sub {
			margin-top: 100rpx;
			color: #666;
			font-size: 28rpx;
			text-align: center;
		}
		.popup-footer {
			display: flex;
			justify-content: space-between;
			margin: 72rpx 52rpx 0;
			.cancle {
				width: 200rpx;
				line-height: 76rpx;
				text-align: center;
				border: 2rpx solid #3F93FF;
				border-radius: 40rpx;
				color: #3F93FF;
			}
			.confim {
				width: 200rpx;
				line-height: 76rpx;
				text-align: center;
				border-radius: 40rpx;
				background: #3F93FF;
				color: #fff;
			}
		}
		input{
			// width: 500rpx;
			margin: 40rpx 40rpx 0;
			padding: 0 30rpx;
			height: 84rpx;
			font-size: 28rpx;
			line-height: 84rpx;
			background: #F4F4F4;
			border-radius: 6rpx 6rpx 6rpx 6rpx;
		}
	}
		
	}
</style>